<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Illuminate\Support\Facades\Auth;
class ShipmentCreateRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return Auth::check();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rl=array(
            'client_company' => 'required',
            'codeno' => 'required|unique:shipments',
            'client_phone' => 'required|numeric',
            'pay' => 'required|numeric',
            'jiaohuo_at' => 'required|date',
            'goods'=>'required'
        );
        if(Request::segment(3)){
            $rl['codeno']='required|unique:shipments,codeno,'.Request::segment(3);
        }
        return $rl;
    }
    public function messages()
    {
        return [
            'client_company.required'=>'请填写客户/单位',
            'codeno.required'=>'请填写出货单号',
            'codeno.unique'=>'出货单号已经存在,请重新填写',
            'client_phone.numeric'=>'请输入正确的联系方式',
            'client_phone.required'=>'请输入联系方式',
            'jiaohuo_at.required'=>'请填写交货日期',
            'jiaohuo_at.date'=>'交货日期格式有误',
            'goods.required'=>'出货产品不能为空',
            'pay.required'=>'请填写已付金额',
            'pay.numeric'=>'已付金额有误',
        ];
        
    }
}
